package com.reserv.db;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;

// DB 접속과 관련된 자원을 해제하거나 트랜잭션 설정을 관리하는 클래스
public class JDBCManager {
	
	public static void closeAll(Connection conn, PreparedStatement pstmt, ResultSet rs) {
		
		try {
			if(rs != null) rs.close();
			if(pstmt != null) pstmt.close();
			if(conn != null) conn.close();
			
		} catch(SQLException e) {
			e.printStackTrace();
		}
	}
	
	public static void setAutoCommit(Connection conn, boolean isTransaction) {
		
		try {
			if(conn != null) conn.setAutoCommit(isTransaction);
			
		} catch(SQLException e) {
			e.printStackTrace();
		}
	}
	
	public static void commit(Connection conn) {
		
		try {
			if(conn != null) conn.commit();
			
		} catch(SQLException e) {
			e.printStackTrace();
		}
	}
	
	public static void rollback(Connection conn) {
		
		try {
			if(conn != null) conn.rollback();
			
		} catch(SQLException e) {
			e.printStackTrace();
		}
	}
}
